//
//  CZStatusToolBar.swift
//  weiBo
//
//  Created by apple on 16/5/14.
//  Copyright © 2016年 itcast. All rights reserved.
//

import UIKit

class CZStatusToolBar: UIView {

    //懒加载控件
    private lazy var retweetButton:UIButton = self.addChildBtn("timeline_icon_retweet", title: "转发")
    //  评论button
    private lazy var commentButton: UIButton = self.addChildBtn("timeline_icon_comment", title: "评论")
    //  赞button
    private lazy var unlikeButton: UIButton = self.addChildBtn("timeline_icon_unlike", title: "赞")
    
    var statusViewModel:CZStatusViewModel? {
        didSet{
            retweetButton.setTitle(statusViewModel?.retweetCountContent, forState: .Normal)
            commentButton.setTitle(statusViewModel?.commentCountContent, forState: .Normal)
            unlikeButton.setTitle(statusViewModel?.unlikeCountContent, forState: .Normal)
        }
        
    }
    
    //设置按钮
    private func addChildBtn(imageName: String , title: String) -> UIButton {
        let btn = UIButton()
        btn.setImage(UIImage(named: imageName), forState: .Normal)
        btn.setBackgroundImage(UIImage(named: "timeline_card_bottom_background"), forState: .Normal)
        btn.adjustsImageWhenHighlighted = false
        btn.setTitle(title, forState: .Normal)
        btn.setTitleColor(UIColor.grayColor(), forState: .Normal)
        btn.titleLabel?.font = UIFont.systemFontOfSize(15)
        addSubview(btn)
        
        return btn
    }


    override init(frame: CGRect) {
        super.init(frame: frame)
        setUpUI()
    }
    
    private func setUpUI(){
        retweetButton.snp_makeConstraints { (make) -> Void in
            make.leading.equalTo(self)
            make.top.equalTo(self)
            make.bottom.equalTo(self)
            make.width.equalTo(commentButton)
        }
        commentButton.snp_makeConstraints { (make) -> Void in
            make.leading.equalTo(retweetButton.snp_trailing)
            make.top.equalTo(self)
            make.bottom.equalTo(self)
            make.width.equalTo(unlikeButton)
        }
        unlikeButton.snp_makeConstraints { (make) -> Void in
            make.trailing.equalTo(self)
            make.top.equalTo(self)
            make.bottom.equalTo(self)
            make.leading.equalTo(commentButton.snp_trailing)
        }
    }
    

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
    
}
